<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>

        let age = ['9','8','4','6','2','5','6','7']

        age.sort((a,b) => a-b)    // a-b升序   b-a降序   不传 第一个字符的升序
        console.log(age);


        let obj = [
            {name:'zs',age:18},
            {name:'ls',age:20},
            {name:'ww',age:15},
            {name:'zl',age:30},
        ]

        obj.sort((a,b) => a.age-b.age)  // 按年龄升序
        console.log(obj);

    </script>

</body>
</html>